﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FlightTicketContract;
using HttpOperation.Crawl.HttpCrawl;
using HttpHelper;
using FlightTicketModel;
using flypeachTicketServer;
using CommonHttpServer;
using flyticketBase;

namespace FlightTicketClient
{
    internal class SchedulerTask
    {
        private IFlightTicket client;

        public SchedulerTask(IFlightTicket client)
        {
            this.client = client;
        }
        public void Test()
        {
            var coo = new System.Net.CookieContainer();
            HttpRequest req = new HttpRequest();

            var tsks = req.CollectHtml("http://localhost:8010/apir/FlightTicket/GetSpiderTask?ip=localhost&count=10", "", "GET", HttpOperation.Crawl.Entity.HtmlEncoding.UTF8, HttpOperation.Crawl.Entity.HtmlEncoding.UTF8, ref coo);
        }
        public List<TicketDetail> WebRequest(FlightTicketChildTask data, out ResponseTag info)
        {
            IQueryTicket q = null;
            //info=new ResponseTag();
            switch (data.Airline.AirlineName)
            {
                case "flypeach":
                    q = new flypeachTicketQuery();
                    break;
                default:
                    break;
            }
            if (q == null)
                throw new ArgumentNullException("IQueryTicket是null或尚未实现对应的功能");
            q.Init();
            string html = q.QueryTicket("KIX", "HKG", false, DateTime.Now.AddDays(23), null);
            //string html = File.ReadAllText(@"C:\Users\Guo\Documents\HBuilderProjects\HelloHBuilder\index.html");
            var list = q.AnalyseHtml(html, out info);

            switch (info.errcode)
            {
                case ErrCode.None:
                    break;
                case ErrCode.Normal:
                    break;
                case ErrCode.NotData:
                    break;
                case ErrCode.HasErr:
                    break;
                case ErrCode.Fatal:
                    break;
                case ErrCode.Forbidden:
                    break;
                default:
                    break;
            }
            return list;
        }
    }
}
